package com.neuedu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/***
 * 项目名称:  MyJDBC 
 * 包：  com.neuedu.jdbc 
 * date:   2025/11/12   10:45  
 * 描述:  
 *  @author : 张金山
 *  作者博客:   https://blog.fulfill.com.cn
 */
public class DBUtils {


    // String url = "http://www.baidu.com";
    public static final String url = "jdbc:mysql://localhost:3306/his?useUnicode=true&characterEncoding=utf8";
    public static final String username = "root";
    public static final String password = "root";
    public static final String driverClass ="com.mysql.cj.jdbc.Driver";





    static{
        try {
            Class.forName(driverClass);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

    }
    /**
     * 创建连接
     * @return
     * @throws ClassNotFoundException
     * @throws SQLException
     */
    public static Connection getConnection() throws ClassNotFoundException, SQLException {


        // 2 创建连接
        Connection conn = DriverManager.getConnection(url, username, password);



        return conn;

    }


}
